package cn.tradewin.advisor.pages.master;
import org.apache.tapestry5.SelectModel;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import cn.tradewin.advisor.commons.selectmodel.CodeLabelSelectModel;
import cn.tradewin.advisor.persist.model.Department;
import cn.tradewin.advisor.persist.services.AccountService;
import cn.tradewin.advisor.persist.services.DeptService;

public class DeptAdd {

	@Property
	private Department dept;

	@Property
	private SelectModel deptOwnerModel;
	
	@Inject
	private AccountService accountService;
	
	@Inject
	private DeptService deptService;

	void onPrepareForRender() {
		deptOwnerModel = new CodeLabelSelectModel(accountService.getAccountsOptions());
	}
	
	void onPrepare() {
		if (dept == null) {
			dept = new Department();
		}
	}

	Object onBack() {
		return DeptBoard.class;
	}

	Object onSubmit() {
		deptService.addDept(dept);
		return DeptBoard.class;
	}	
}